﻿package com.cilico.view;

import com.cilico.Mid;
import com.cilico.components.ComponentListener;
import com.cilico.components.mButton;
import com.cilico.components.ImageItem;
import com.cilico.components.Select;
import com.cilico.components.Table;
import com.cilico.utils.Utils;

import android.view.View;

public class LoginController implements ComponentListener {
	private Mid mid_;
	private LoginView loginView_;

	public LoginController(LoginView temp) {
		mid_ = BaseView.mid_;
		loginView_ = temp;
	}

	public boolean componentAction(View component, BaseView bv) {
		boolean isAction = true;
		if (component instanceof mButton) {
			return GeneralController.disposeButtonEvent(component, loginView_);
		} else if (component instanceof Table) {
			return GeneralController.disposeTableEvent(component, loginView_);
		} else if (component instanceof ImageItem){
			if (((ImageItem)component).linkAddr_ !=null && !((ImageItem)component).linkAddr_.equals("")){
				mid_.channelEntity_.changeChannel(((ImageItem)component).linkAddr_, loginView_, ((ImageItem)component).isMove_);
			} 
		} else if (component instanceof Select){
			Select select = (Select) component;
			Utils.printOutToConsole("actionUrl_ = " + select.actionUrl_);
			if (select.actionUrl_ == null) {
				return false;
			}
			StringBuffer linkB = new StringBuffer(select.actionUrl_);
			linkB.append("&");
			linkB.append(select.attrName_);
			linkB.append("=");
			if(select.optionValue_.indexOf('+') != -1) {
				int index = select.optionValue_.indexOf('+');
				linkB.append(select.optionValue_.substring(0, index));
				linkB.append('%');
				linkB.append("2B");
				linkB.append(select.optionValue_.substring(index + 1));
			} else {
				linkB.append(select.optionValue_);
			}
			loginView_.dealWithLink(linkB.toString(), loginView_, false);
		}
		return isAction;
	}

}
